﻿<UserControl x:Class="DBSchemaViewer.FrontEnd.DiagramUserControls.CtlDBTable"             
    xmlns:converters="clr-namespace:DBSchemaViewer.FrontEnd.DiagramUserControls.Converters"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="270">

    <UserControl.Resources>
        <converters:PKConverter x:Key="PKConverter" />
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" Background="White" Height="300">
        <Border x:Name="bdBorder" 
                CornerRadius="5"  
                BorderThickness="2" 
                Canvas.Top="0" 
                BorderBrush="#7A786B" 
                Canvas.Left="0" 
                Height="300"                
                >
            <Canvas x:Name="cvBoxContainer" 
                    MouseLeftButtonDown="Heading_MouseLeftButtonDown"
             >
                <Canvas x:Name="cvTitleHeader" Canvas.Top="0" Canvas.Left="0" Width="265" Height="20">
                    <Canvas.Background>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                            <GradientStop Color="#D3DCEF" Offset="0.0" />
                            <GradientStop Color="#EAEEF7" Offset="0.5" />                            
                            <GradientStop Color="#FFFFFF" Offset="1.0" />
                        </LinearGradientBrush>    
                    </Canvas.Background>       
                    <TextBlock x:Name="tbTitleHeaderText" Text="Table Name" Foreground="Black" FontWeight="bold"/>                                            
                    
                    <Line Canvas.Top="20" Canvas.Left="0" Stroke="#F0F2F9" StrokeThickness="2"
                          X1="0" X2="265" Y1="0" Y2="0"  
                    />                                            
            </Canvas>


                <Grid x:Name="grFields" 
                  Margin="0"                  
                  VerticalAlignment="Top"
                  Canvas.Top="20" 
                  Canvas.Left="0" 
                  ShowGridLines="True" 
                  Width="265"
                  Height="275" 
                  Background="White"
                  
                  >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="275"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MinWidth="265"/>
                    </Grid.ColumnDefinitions>

                    <data:DataGrid x:Name="dgFields"  
                               Margin="0"
                               Canvas.Top="0"
                               Canvas.Left="0"
                               Grid.Row="0" 
                               Grid.Column="0"                                
                               IsReadOnly="True"
                               HeadersVisibility="Column" 
                               GridLinesVisibility="All"                               
                               SelectionMode="Single"
                               RowHeight="22"                               
                               Width="265"
                               Height="270"
                               VerticalScrollBarVisibility="Hidden"
                               VerticalContentAlignment="Top" 
                               HorizontalScrollBarVisibility="Hidden"
                               AutoGenerateColumns="False"
                                    
                               >

                        <data:DataGrid.Columns>
                            <data:DataGridTemplateColumn Width="35"  Header="PK">
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock x:Name="txKeyInfo"                                                                                                   
                                                 Text="{Binding IsPrimaryKey, Converter={StaticResource PKConverter}}"                                                                                                   
                                                 MouseLeftButtonDown="FieldTextBoxColumn_MouseLeftButtonDown"                                                 
                                                 MouseLeftButtonUp="FieldTextBoxColumn_MouseLeftButtonUp"
                                                 />

                                        <!--<TextBox x:Name="txKeyInfo" 
                                                 IsReadOnly="True" 
                                                 
                                                 Text="{Binding IsPrimaryKey, Converter={StaticResource PKConverter}}"                                                  
                                                 IsTabStop="False" 
                                                 MouseLeftButtonDown="FieldTextBoxColumn_MouseLeftButtonDown"                                                 
                                                 MouseLeftButtonUp="FieldTextBoxColumn_MouseLeftButtonUp"
                                                 />                                                                                            
                                        -->
                                </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>

                            <data:DataGridTemplateColumn Width="222"   Header="Field">
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock x:Name="txFieldName"
                                            Text="{Binding FieldName}"                                             
                                             MouseLeftButtonDown="FieldTextBoxColumn_MouseLeftButtonDown"
                                             MouseLeftButtonUp="FieldTextBoxColumn_MouseLeftButtonUp"                                             
                                             />

                                        <!--<TextBox x:Name="txFieldName"
                                            Text="{Binding FieldName}" IsReadOnly="True" 
                                             IsTabStop="False" 
                                             MouseLeftButtonDown="FieldTextBoxColumn_MouseLeftButtonDown"
                                             MouseLeftButtonUp="FieldTextBoxColumn_MouseLeftButtonUp"                                             
                                             />-->
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>

                        </data:DataGrid.Columns>

                    </data:DataGrid>


                </Grid>
            </Canvas>
        </Border>

    </Grid>
</UserControl>
